﻿<Window x:Class="Com.CodePlex.SPPower.View.MainWindowView"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
		xmlns:localv="clr-namespace:Com.CodePlex.SPPower.View"
		xmlns:localvm="clr-namespace:Com.CodePlex.SPPower.ViewModel"
		xmlns:localc="clr-namespace:Com.CodePlex.SPPower.Controller"
		Title="{Binding Path=DisplayName}"
		WindowStartupLocation="CenterScreen"
		mc:Ignorable="d"
		d:DesignHeight="300" 
		d:DesignWidth="600">
	<Window.Resources>
		<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
		<DataTemplate x:Key="StringTemplate">
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition MinWidth="100" Width="100" SharedSizeGroup="Column1"/>
					<ColumnDefinition MinWidth="200" Width="300" SharedSizeGroup="Column2"/>
				</Grid.ColumnDefinitions>
				<TextBlock Grid.Column="0" Text="{Binding DisplayName}"/>
				<TextBox Grid.Column="1" Text="{Binding Value, Mode=TwoWay}" />
			</Grid>
		</DataTemplate>
        <DataTemplate x:Key="CheckBoxTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="Column1"/>
                    <ColumnDefinition SharedSizeGroup="Column2"/>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="{Binding DisplayName}"/>
                <CheckBox Grid.Column="1" IsChecked="{Binding Path=Value, Mode=TwoWay}" />
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="ComboBoxTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="Column1"/>
                    <ColumnDefinition SharedSizeGroup="Column2"/>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="{Binding DisplayName}"/>
                <ComboBox Grid.Column="1" />
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="UnknownTemplate">
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition SharedSizeGroup="Column1"/>
					<ColumnDefinition SharedSizeGroup="Column2"/>
				</Grid.ColumnDefinitions>
				<TextBlock Grid.Column="0" Text="{Binding DisplayName}" />
				<TextBlock Grid.Column="1" Text="{Binding Type}"/>
			</Grid>
		</DataTemplate>
		<localv:CmdParameterTemplateSelector x:Key="CmdParameterTemplateSelector" 
											 StringTemplate="{StaticResource StringTemplate}" 
											 CheckBoxTemplate="{StaticResource CheckBoxTemplate}"
                                             ComboBoxTemplate="{StaticResource ComboBoxTemplate}"
											 UnknownTemplate="{StaticResource UnknownTemplate}"/>
	</Window.Resources>
	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition Height="*"/>
			<RowDefinition Height="Auto"/>
		</Grid.RowDefinitions>
		<DockPanel Grid.Row="0" HorizontalAlignment="Stretch" Width="Auto" LastChildFill="False" AllowDrop="False" IsItemsHost="False">
			<Menu DockPanel.Dock="Top" KeyboardNavigation.TabNavigation="Cycle">
				<MenuItem Header="_File">
					<MenuItem Header="E_xit" Command="{Binding Path=ExitCommand}" />
				</MenuItem>
				<MenuItem Header="_Help" >
					<MenuItem Header="About" Command="{Binding Path=AboutCommand}" />
				</MenuItem>
			</Menu>
		</DockPanel>
		<Grid Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width=".33*" MinWidth="200" />
				<ColumnDefinition Width="Auto" />
				<ColumnDefinition Width=".66*" MinWidth="200" />
			</Grid.ColumnDefinitions>
			<TreeView Grid.Column="0" HorizontalAlignment="Stretch" Name="treeView1" VerticalAlignment="Stretch" ItemsSource="{Binding TreeRootItems}">
				<TreeView.ItemContainerStyle>
					<Style TargetType="{x:Type TreeViewItem}">
						<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
						<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
						<Setter Property="localv:TreeViewItemBehavior.IsBroughtIntoViewWhenSelected" Value="True" />
					</Style>
				</TreeView.ItemContainerStyle>
				<TreeView.Resources>
					<HierarchicalDataTemplate DataType="{x:Type localvm:ViewModel}" ItemsSource="{Binding Children}">
						<StackPanel Orientation="Horizontal">
							<Image Source="{Binding Path=ImageSource}" Height="14" Width="14"></Image>
							<TextBlock Text="{Binding Path=DisplayName}" Margin="5,0" />
						</StackPanel>
					</HierarchicalDataTemplate>
				</TreeView.Resources>
			</TreeView>
			<GridSplitter Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Stretch" ResizeBehavior="PreviousAndNext" Width="5" Background="#FFBCBCBC"/>
			<Grid Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
				<Grid.RowDefinitions>
					<RowDefinition Height=".60*" MinHeight="100" />
					<RowDefinition Height="Auto" />
					<RowDefinition Height=".40*" MinHeight="100" />
				</Grid.RowDefinitions>
				<ScrollViewer Grid.Row="0" CanContentScroll="False" Visibility="{Binding ParametersVisiblity}" >
					<StackPanel HorizontalAlignment="Stretch">
						<ItemsControl Grid.IsSharedSizeScope="True" ItemsSource="{Binding Path=Parameters}" ItemTemplateSelector="{StaticResource CmdParameterTemplateSelector}">
						</ItemsControl>
						<StackPanel Orientation="Horizontal">
							<Button Command="{Binding RunCommand}" Content="Execute" />
						</StackPanel>
					</StackPanel>
				</ScrollViewer>
				<GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" ResizeBehavior="PreviousAndNext" Height="5" Background="#FFBCBCBC"/>
				<Grid Grid.Row="2">
					<ScrollViewer x:Name="historyScroll" CanContentScroll="False" VerticalScrollBarVisibility="Visible">
						<ItemsControl x:Name="historyItems" ItemsSource="{Binding Path=History}">
							<ItemsControl.ItemTemplate>
								<DataTemplate>
									<Expander IsExpanded="{Binding IsExpanded,Mode=TwoWay}">
										<Expander.Header>
											<Grid Width="525">
												<Grid.ColumnDefinitions>
													<ColumnDefinition Width="*" />
													<ColumnDefinition Width="50" />
                                                    <ColumnDefinition Width="50" />
												</Grid.ColumnDefinitions>
												<TextBlock Grid.Column="0" Text="{Binding DisplayName}" Background="AntiqueWhite" Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}}, Path=ActualWidth}" />
                                                <Button Grid.Column="1" Command="{Binding LoadCommand}" Content="Load" />
                                                <Button Grid.Column="2" Command="{Binding DeleteCommand}" Content="Delete" />
											</Grid>
										</Expander.Header>
										<StackPanel Margin="10,4,0,0">
											<TextBox localv:MainWindowViewHelper.IsAutoScroll="{Binding IsAutoScroll}" BorderThickness="0" Height="150" IsReadOnly="True" Text="{Binding Log}" VerticalScrollBarVisibility="Visible" />
										</StackPanel>
									</Expander>
								</DataTemplate>
							</ItemsControl.ItemTemplate>
						</ItemsControl>
					</ScrollViewer>
				</Grid>
			</Grid>
		</Grid>
		<StatusBar Grid.Row="2" Height="28">
			<StatusBarItem Content="{Binding StatusBarText}" />
			<StatusBarItem HorizontalAlignment="Right">
				<ProgressBar 
						Width="100" 
						Height="16"
						Minimum="0" Maximum="100"
						Visibility="{Binding IsProgressBarVisible,Converter={StaticResource BooleanToVisibilityConverter}}"
						IsIndeterminate="True" />
			</StatusBarItem>
		</StatusBar>
	</Grid>
</Window>
